﻿using System;
using System.IO;

namespace Infrastructure.Diagnostics
{
    public class TextWriterLogListener : ILogListener
    {
        private TextWriter m_textWriter;

        public TextWriterLogListener(string path)
        {
            var sr = new StreamWriter(path);
            sr.AutoFlush = true;
            m_textWriter = sr;
        }

        public void LogEntry(ILogEntry entry)
        {
            var message = string.Format("{0} | {1} | {2}.{3} | {4}",
                entry.OccuranceTime.ToString("yyyy/MM/dd HH:mm:ss.ff"),
                entry.Severity.ToString(),
                entry.Caller.DeclaringType.FullName,
                entry.Caller.Name,
                entry.Message);
            m_textWriter.WriteLine(message);
        }
    }
}
